package com.yumijinfu.tool;

import com.yumijinfu.base.BaseActivity;

import java.util.LinkedList;
import java.util.List;

/**
 * 作者：黑哥 on 2016/7/29 10:05
 */
public class AbActivityManager {

    private List<BaseActivity> activityList = new LinkedList<BaseActivity>();
    private static AbActivityManager instance;

    private AbActivityManager() {
    }

    /**
     * 单例模式中获取唯一的AbActivityManager实例.
     * @return
     */
    public static AbActivityManager getInstance() {
        if (null == instance) {
            instance = new AbActivityManager();
        }
        return instance;
    }

    public List<BaseActivity> getActivityList() {
        return activityList;
    }

    /**
     * 添加Activity到容器中.
     * @param activity
     */
    public void addActivity(BaseActivity activity) {
        activityList.add(activity);
    }

    /**
     * 移除Activity从容器中.
     * @param activity
     */
    public void removeActivity(BaseActivity activity) {
        activityList.remove(activity);
    }

    /**
     * 遍历所有Activity并finish.
     */
    public void clearAllActivity() {
        for (BaseActivity activity : activityList) {
            if(activity!=null){
                activity.finish();
            }
        }
    }

}
